package com.bi.autotest.operations.operations_open;

import com.auto.base.OperateAppium;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.JavascriptExecutor;

public class PayProcessOpenOperation extends OperateAppium {

    public PayProcessOpenOperation(AndroidDriver androidDriver) {
        super(androidDriver);
    }

    //输入微信支付密码
    public void passWord() {
        print("输入微信支付密码");
        if(driver.getContext().equals("WEBVIEW_com.tencent.mm:tools")){
            switchAppContext();
        }
        //112233
        sleep(1000);
        press(180, 1343);
        sleep(1000);
        press(180, 1343);
        sleep(1000);
        press(540, 1343);
        sleep(1000);
        press(540, 1343);
        sleep(1000);
        press(900, 1343);
        sleep(1000);
        press(900, 1343);
        sleep(1000);

       /* //200811
        sleep(1000);
        press(540, 1343);

        sleep(1000);
        press(180, 1343);
        sleep(1000);
        press(180, 1343);*/

    }

    /**
     * H5 自助付款 按键输入付款金额
     * @param money 正数最多有两位小数
     */
    public void click_InputMoney(String money) {
        if(driver.getContext().equals("WEBVIEW_com.tencent.mm:tools")){
            switchAppContext();
        }
        char[] chars = money.toCharArray();
        for (char c:chars) {
            switch (c){
                case '1' :
                    press(138, 1422);
                    sleep(1000);
                    break;
                case '2' :
                    press(413, 1422);
                    sleep(1000);
                    break;
                case '3' :
                    press(690, 1422);
                    sleep(1000);
                    break;
                case '4' :
                    press(138, 1564);
                    sleep(1000);
                    break;
                case '5' :
                    press(413, 1564);
                    sleep(1000);
                    break;
                case '6' :
                    press(690, 1564);
                    sleep(1000);
                    break;
                case '7' :
                    press(138, 1707);
                    sleep(1000);
                    break;
                case '8' :
                    press(413, 1707);
                    sleep(1000);
                    break;
                case '9' :
                    press(690, 1707);
                    sleep(1000);
                    break;
                case '0' :
                    press(277, 1850);
                    sleep(1000);
                    break;
                case '.' :
                    press(690, 1850);
                    sleep(1000);
                    break;
                default :
                    System.out.println("这个数字有误");
                    return;
            }
        }
        //确认付款
        press(971, 1779);
        sleep(3000);
    }

    /**
     * 活动周期时间设置
     * 时间格式：yyyy-mm-dd  时间不能小于当前时间
     * @param startDate  周期开始时间
     * @param endDate    周期结束时间
     */
    public void setActivityDate(String startDate,String endDate) {
        JavascriptExecutor js = driver;
        js.executeScript("document.getElementById('startDate').setAttribute('value', '"+startDate+"')");
        js.executeScript("document.getElementById('endDate').setAttribute('value', '"+endDate+"')");
    }



}
